package com.yh.rent.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yh.rent.biz.impl.HouseBizImpl;
import com.yh.rent.biz.impl.StreetBizImpl;
import com.yh.rent.biz.impl.TypeBizImpl;
import com.yh.rent.entity.House;
import com.yh.rent.entity.Street;
import com.yh.rent.entity.Type;

/**
 * Servlet implementation class DetailsServlet
 */
public class DetailsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DetailsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String id = request.getParameter("id");
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path
				+ "/";
		House house = new HouseBizImpl().getHouseById(Integer.valueOf(id)) ;
		
		//获取所有道路
		List<Type> tlist = new TypeBizImpl().getAllTypes() ;
		List<Street> slist = new StreetBizImpl().getAllStreets() ;
		request.setAttribute("slist", slist);
		request.setAttribute("tlist", tlist);
		request.setAttribute("idhouse", house);
		request.setAttribute("basePath", basePath);
		request.getRequestDispatcher("/WEB-INF/templates/details.ftl").forward(request, response);;
	}

}
